/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package com.pancho;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class ResponseDAO {
	public static Response loadResponseByORMID(int idResponse) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadResponseByORMID(session, idResponse);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response getResponseByORMID(int idResponse) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getResponseByORMID(session, idResponse);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByORMID(int idResponse, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadResponseByORMID(session, idResponse, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response getResponseByORMID(int idResponse, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getResponseByORMID(session, idResponse, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByORMID(PersistentSession session, int idResponse) throws PersistentException {
		try {
			return (Response) session.load(com.pancho.Response.class, new Integer(idResponse));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response getResponseByORMID(PersistentSession session, int idResponse) throws PersistentException {
		try {
			return (Response) session.get(com.pancho.Response.class, new Integer(idResponse));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByORMID(PersistentSession session, int idResponse, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Response) session.load(com.pancho.Response.class, new Integer(idResponse), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response getResponseByORMID(PersistentSession session, int idResponse, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Response) session.get(com.pancho.Response.class, new Integer(idResponse), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response[] listResponseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listResponseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response[] listResponseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listResponseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response[] listResponseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Response as Response");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Response[]) list.toArray(new Response[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response[] listResponseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Response as Response");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Response[]) list.toArray(new Response[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadResponseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadResponseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Response[] responses = listResponseByQuery(session, condition, orderBy);
		if (responses != null && responses.length > 0)
			return responses[0];
		else
			return null;
	}
	
	public static Response loadResponseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Response[] responses = listResponseByQuery(session, condition, orderBy, lockMode);
		if (responses != null && responses.length > 0)
			return responses[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateResponseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateResponseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateResponseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateResponseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateResponseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Response as Response");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateResponseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Response as Response");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response createResponse() {
		return new com.pancho.Response();
	}
	
	public static boolean save(com.pancho.Response response) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().saveObject(response);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(com.pancho.Response response) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().deleteObject(response);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.Response response)throws PersistentException {
		try {
			if(response.getPacientidPaciente() != null) {
				response.getPacientidPaciente().setResponse(null);
			}
			
			if(response.getQuestionidQuest() != null) {
				response.getQuestionidQuest().response.remove(response);
			}
			
			return delete(response);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.Response response, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(response.getPacientidPaciente() != null) {
				response.getPacientidPaciente().setResponse(null);
			}
			
			if(response.getQuestionidQuest() != null) {
				response.getQuestionidQuest().response.remove(response);
			}
			
			try {
				session.delete(response);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(com.pancho.Response response) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().refresh(response);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(com.pancho.Response response) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().evict(response);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Response loadResponseByCriteria(ResponseCriteria responseCriteria) {
		Response[] responses = listResponseByCriteria(responseCriteria);
		if(responses == null || responses.length == 0) {
			return null;
		}
		return responses[0];
	}
	
	public static Response[] listResponseByCriteria(ResponseCriteria responseCriteria) {
		return responseCriteria.listResponse();
	}
}
